<%@ page language="java"
		 import="com.ruohi.manage.DBType,com.ruohi.manage.PoolManager,com.ruohi.util.common.CommonString,com.ruohi.util.common.Env,com.ruohi.util.dbutil.DBHelper,java.sql.Connection"
		 pageEncoding="UTF-8" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.TreeMap" %>
<%
	Connection connection = null;
	DBHelper dbHelper = DBHelper.getInstance();
	Map model = new HashMap();
	
	Map adminInfo = (Map)session.getAttribute("adminInfo");
	Map channels = new TreeMap();
	try{
		connection = PoolManager.getConnection(DBType.BUSINESS);
		String uuid = CommonString.getFormatPara(request.getParameter("channel_uuid"));
		
		//按状态
		String totalSql = "select order_status,count(id) as count,sum(product_total_price+ship_total_price) as total_sale from gift_order group by order_status ";
		List<Map> totalList =  dbHelper.getMapList(totalSql, connection);
		
		//按来源
		String totalSql2 = "select pay_gateway_no,count(id) as count,sum(product_total_price+ship_total_price) as total_sale from gift_order where order_status=5 group by pay_gateway_no order by pay_gateway_no ";
		List<Map> totalList2 =  dbHelper.getMapList(totalSql2, connection);
		
		
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
     <link rel="stylesheet" href="/plugin/ui/jqueryUI/themes/base/jquery.ui.all.css" />
    <link rel="stylesheet" type="text/css" href="/plugin/editor/ueditor/themes/default/ueditor.css"/>
     <link rel="stylesheet" type="text/css" href="/plugin/tree/ztree/zTreeStyle/zTreeStyle.css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
	<script src="/plugin/ui/jqueryUI/jquery-ui-1.8.20.custom.min.js"></script>
    <style type="text/css">
    	#template {
			display: none;
			width: 350px;
			height: 340px;
			border: 1px solid #ccc;
			position: relative;
			top: -364px;
			left: 0px;
			background: #fff;
			overflow-y: scroll;
			overflow-x: hidden;
			z-index: 99999;
		}
		
		#template_channel {
			display: none;width: 350px;
			height: 340px;
			border: 1px solid #ccc;
			position: relative;
			top: -64px;
			left: 0px;
			background: #fff;
			overflow-y: scroll;
			overflow-x: hidden;
			z-index: 99999;
		}
		
		#template_close {
			display: none;
			width: 30px;
			height: 16px;
			border: 1px solid #ccc;
			position: relative;
			top: -706px;
			z-index:9999;
			left: 352px;
			cursor: pointer;
			font-weight: bold;
			background-color: #eee;
		}
	
    </style>
     <style type="text/css">
    .tableStyle01 { width:1000px; border-collapse:collapse; border:#ccc 1px solid; margin:0px auto; clear:both;}
    .tableStyle01 td,.tableStyle01 th { border:#ccc 1px solid; text-align:left; padding:3px 5px; line-height:18px;}
    .tableStyle01 th { font-weight:bold; background-color:#dddddd; color:#000;}
    </style>
    
  </head>
  
  <body style="margin: 0;padding: 0; overflow-x: hidden; ">
	  <div id="layout1">
		  <div position="left"
		  <%--title="<div class='l-toolbar-item l-panel-btn l-toolbar-item-hasicon' style='font-size:12px;font-weight:normal;position: relative;top:-4px;'><span>更新提现金额</span><div class='l-panel-btn-l'></div><div class='l-panel-btn-r'></div><div class='l-icon l-icon-save'></div></div>"--%>
		  >
	    	<form name="theform" id="theform" action="/backend/action/crud.jsp">
		<div class="formDiv" style="overflow-y:scroll; ">
				<div class="group">
					<span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span>
					<span class="groupTitle">订单状态统计信息</span>
				</div>
				<div style="clear: left;"></div>
				<div class="formRight" style="height:200px;">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableStyle01" id="paramTable" lang="'no':'','name':''">
			        <tbody>
			        <tr>
			          <th width="30%" style="text-align:center">订单状态</th>
			          <th width="25%" style="text-align:center">数量（个）</th>
			          <th width="25%" style="text-align:center">金额（元）</th>
			        </tr>
			        <%
			        	if(totalList!=null){
			        		for(Map m : totalList){
			        			String order_status = CommonString.getFormatPara(m.get("order_status"));
			        			int count = CommonString.getFormatInt(m.get("count"));
			        			double total_sale = CommonString.getFormatDouble(m.get("total_sale"));
			        			String order_status_name = "";
			        			if(order_status.equals("0")){
			        				order_status_name = "已取消";
			        			}else if(order_status.equals("1")){
			        				order_status_name = "等待付款";
			        			}else if(order_status.equals("2")){
			        				order_status_name = "已付款";
			        			}else if(order_status.equals("3")){
			        				order_status_name = "配货中";
			        			}else if(order_status.equals("4")){
			        				order_status_name = "已发货";
			        			}else if(order_status.equals("5")){
			        				order_status_name = "已完成";
			        			}else if(order_status.equals("6")){
			        				order_status_name = "已退款";
			        			}
			        %>
		        	<tr>
		        	  <td style="text-align:center"><%=order_status_name %></td>
			          <td style="text-align:right"><%=count %></td>
			          <td style="text-align:right"><%=total_sale %></td>
			        </tr>
			        <%}} %>

			      </tbody>
			      </table>
			      </div>
				<div style="clear:left;"></div>
				<div class="group">
					<span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span>
					<span class="groupTitle">订单来源统计信息</span>
				</div>
				<div style="clear: left;"></div>
				<div class="formRight" style="height:200px;">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableStyle01" id="paramTable" lang="'no':'','name':''">
			        <tbody>
			        <tr>
			          <th width="30%" style="text-align:center">订单来源</th>
			          <th width="25%" style="text-align:center">数量（个）</th>
			          <th width="25%" style="text-align:center">金额（元）</th>
			        </tr>
			        <%
			        int null_count = 0; 
			        double null_sales = 0.0;
			        int zhifubao_count = 0; 
			        double zhifubao_sales = 0.0;
			        int zhifubao_m_count = 0; 
			        double zhifubao_m_sales = 0.0;
			        int weixin_count = 0; 
			        double weixin_sales = 0.0;
			        int other_count = 0; 
			        double other_sales = 0.0;
			        	if(totalList2!=null){
			        		for(Map m : totalList2){
			        			String pay_gateway_no = CommonString.getFormatPara(m.get("pay_gateway_no"));
			        			int count = CommonString.getFormatInt(m.get("count"));
			        			double total_sale = CommonString.getFormatDouble(m.get("total_sale"));
			        			if(pay_gateway_no.equals("")){
			        				null_count += count;
			        				null_sales += total_sale;
			        			}else if(pay_gateway_no.equals("Alipay")){
			        				zhifubao_count += count;
			        				zhifubao_sales += total_sale;
			        			}else if(pay_gateway_no.equals("AlipayM")){
			        				zhifubao_m_count += count;
			        				zhifubao_m_sales += total_sale;
			        			}else if(pay_gateway_no.equals("WX_M")){
			        				weixin_count += count;
			        				weixin_sales += total_sale;
			        			}else{
			        				other_count += count;
			        				other_sales += total_sale;
			        			}
			        }} 
			        %>
			        <tr>
		        	  <td style="text-align:center">支付宝</td>
			          <td style="text-align:right"><%=zhifubao_count %></td>
			          <td style="text-align:right"><%=zhifubao_sales %></td>
			        </tr>
			        <tr>
		        	  <td style="text-align:center">支付宝移动端</td>
			          <td style="text-align:right"><%=zhifubao_m_count %></td>
			          <td style="text-align:right"><%=zhifubao_m_sales %></td>
			        </tr>
			        <tr>
		        	  <td style="text-align:center">微信</td>
			          <td style="text-align:right"><%=weixin_count %></td>
			          <td style="text-align:right"><%=weixin_sales %></td>
			        </tr>
			        <tr>
		        	  <td style="text-align:center">网银</td>
			          <td style="text-align:right"><%=other_count %></td>
			          <td style="text-align:right"><%=other_sales %></td>
			        </tr>
			        <tr>
		        	  <td style="text-align:center">其他</td>
			          <td style="text-align:right"><%=null_count %></td>
			          <td style="text-align:right"><%=null_sales %></td>
			        </tr>

			      </tbody>
			      </table>
			      </div>
				<div style="clear:left;"></div>	
		</div>
		<div style="clear: left;"></div>
		<input type="hidden" name="tableName" id="tableName" value="" />
		<input type="hidden" name="zd_id" id="zd_id" value="<%=CommonString.getFormatPara(model.get("id")) %>" />
		<input type="hidden" name="zd_order_no" id="zd_order_no" value="<%=CommonString.getFormatPara(model.get("order_no")) %>" />
		<input type="hidden" name="eventAfter" value="createChannel" />
	</form>
	    </div>
	    <!-- 
	    <div position="center" id="center" title="元素管理">
	    <div class="extensioninfo">
	    	<ul>
				<li class="ui-state-default" onclick='jrWindow("/backend/common_template/common_template_list.jsp?channel_uuid=<%=uuid %>","扩展模板",800,500);'><span class="ui-icon ui-icon-arrowthick-2-n-s" style="float: left;"></span>&nbsp;<span style="float:left; margin-top: 1px;">扩展模板</span></li>
	    	</ul>
	    </div>
	    </div>
	     -->
	   </div>
  </body>
</html>
<script type="text/javascript" src="/plugin/jquery/jquery.form.js"></script>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" type="text/javascript"></script>
<script src="/plugin/tree/ztree/jquery.ztree.all-3.1.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/editor/ueditor/editor_config.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/editor/ueditor/editor_all_min.js"></script>
<script type="text/javascript">
	jQuery("#sortable").sortable({
		stop : function(event, ui) {
			doSort();
		}
	});
	jQuery("#sortable").disableSelection();
	jQuery("#layout1").ligerLayout({
		leftWidth : "100%",
		centerWidth : "0%",
		isLeftCollapse : false,
		allowLeftCollapse : false,
		allowLeftResize : false
	});
	jQuery(".formDiv").height(jQuery(document).height()-50);
	function doSub(){
		jQuery("#theform").ajaxSubmit({
			type : "POST",
            async : false ,
			success : function(data) {
				var rs = parseInt(jQuery.trim(data), 10);
				if (rs > 0) {
					jrSuccess("保存成功！");
					<%
					if("".equals(CommonString.getFormatPara(model.get("id")))){
						%>
					window.location.reload();
						<%
					}
					%>
				} 
			}
		});
	}

	var zTreeNodes = [
	];

	
	var setting = {
		view: {
			dblClickExpand: false,
			showLine: true,
			selectedMulti: false,
			expandSpeed: (jQuery.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
		},
		data: {
			simpleData: {
				enable:true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: "template"
			}
		}
	};
	jQuery.fn.zTree.init(jQuery("#ztree"), setting, zTreeNodes);
	
	
	var channelNodes = [
		{ id:'0', pId:'-1', name:'无父栏目',click:"setPar('4CCDF227-7F10-4E09-A47C-085CCB4A45FF','无父栏目')",open:true},
	];
	
	jQuery.fn.zTree.init(jQuery("#lanmu"), setting, channelNodes);
	
	
	jQuery("#fulanmu").click(function(){
		jQuery("#template_channel").show();
	});
	
	function chooseTemplate(file){
		jQuery("#zd_template_file_name").val(file);
		jQuery("#zd_create_file_name").val(file);
	}
	
	function showDiv(){
		hideDiv();
		jQuery("#template,#template_close").show();
	}
	
	function hideDiv(){
		jQuery("#template,#template_close").hide();
	}
	
	jQuery("#template_close").click(function(){
		hideDiv();
	});
	
	jQuery("#zd_template_file_name").click(function(){
		var dis = jQuery("#template").css("display");
		if(dis=='none'){
			showDiv();
		}
	});

	//编辑扩展列表信息
	function viewExtensionListInfo(subblock_uuid,title){
		jrWindow("/backend/common_channel_subblock_data/common_channel_subblock_data_list.jsp?subblock_uuid="+subblock_uuid,title,700,400);
	}
	//编辑扩展单条信息
	function viewExtensionSingleInfo(subblock_uuid,title){
		jrWindow("/backend/common_channel_subblock_data/common_channel_subblock_data_edit.jsp?subblock_uuid="+subblock_uuid,title,680,500);
	}
	
	function doSort(){
		var sortHtml = "";
		jQuery.each(jQuery("#sortable li"),function(index,data){
			sortHtml += jQuery(this).attr("myid")+",";
		});
		sortHtml = sortHtml.substring(0,sortHtml.length-1);
		jQuery.ajax({
			url:"/backend/action/ajax_cud.jsp",
			type:"post",
			data:{'flag':'saveSort',"tableName":"service_common_channel_subblock","sortId":sortHtml},
			async:false,
			cache:false
		});
	}
	jQuery(".l-toolbar-item").click(function(){
		refreshPayment();
	});
	jQuery(".l-toolbar-item").hover(function(){
		jQuery(this).addClass("l-panel-btn-over");
	},function(){
		jQuery(this).removeClass("l-panel-btn-over");
	});
	function setPar(uuid,name){
		jQuery("#fulanmu").val(name);
		jQuery("#zd_parent_uuid").val(uuid);
		jQuery("#template_channel").hide();
	}
	
	//更新合伙人提现金额
	function refreshPayment(){
		if(confirm("确定更新提现金额吗？")){
			jQuery.ajax({
				type:"post",
				url:"/backend/action/ajax_r.jsp",
				data:{flag:"getRefreshPayment",enumNo:"106013"},
				success:function(msg){
					if(''!=jQuery.trim(msg)){
						alert("更新成功！");
						grid.loadData();
					}
				}
			});
		}
	}
</script><%
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		DBHelper.freeConnection(connection);
	}
%>